<template>
  <div class="page">
    <div class="head">
      <h1><span v-if="isAll == 1">全服</span>{{$t('战斗记录')}}</h1>
    </div>
    <div class="panel" v-for="(item,index) in records" :key="index">
      <div class="info">
        <p>大圣 #{{ item.realityMonkeyId }} <span>VS</span> 猕猴 #{{ item.fakeMonkeyId }}</p>
      </div>
      <div class="property" v-if="item.status != 0">
        <span>成长+{{item.grow}}</span>
        <span>生育+{{item.bear}}</span>
        <span>力量+{{item.money}}</span>
        <span>体重+{{item.weight}}</span>
      </div>
      <div class="status">
        <span>{{ item.createTime | formatTime }}</span>
        <span :class="item.status == 0 ? 'green':'red'">{{ type[item.status] }}</span>
      </div>
    </div>
    <infinite-loading @infinite="initData" ref="infiniteLoading2">
      <span slot="no-more"></span>
      <div slot="no-results">
        <br>
        <empty></empty>
      </div>
      <spinner slot="spinner" type="lines"></spinner>
    </infinite-loading>
  </div>
</template>

<i18n>
猴毛记录:
  en: Monkey hair records
收入:
  en: income
支出:
  en: outcome
</i18n>
<script>
  import {
    Spinner
  } from 'vux'
  import empty from './common/empty.vue'
  import InfiniteLoading from 'vue-infinite-loading';
  export default {
    components: {
      empty,
      InfiniteLoading,
      Spinner
    },
    data() {
      return {
        records: [],
        current: 1,
        type: ['战败', '胜利', '大获全胜！'],
        isAll: ''
      }
    },
    mounted() {
      this.$nextTick(function() {
        this.isAll = this.$route.query.t
      });
    },
    methods: {
      initData($state) {
        this.$http
          .post(`/game/fightRecordPage`, {
            current: this.current,
            all: this.isAll
          })
          .then(res => {
            if (res.code == 200) {
              if (res.result.total > 0) {
                this.records = this.records.concat(res.result.records);
                $state.loaded();
                if (res.result.current < res.result.pages) {
                  this.current += 1;
                } else {
                  $state.complete();
                }
              } else {
                $state.complete();
              }
            } else {}
          })
          .catch(function(error) {});
      }
    }
  }
</script>

<style lang="scss" scoped>
  .panel {
    padding: 8px;
  }
  .info {
    color: $tmdark;
    p {
      font-size: 14px;
      span {
        color: $red;
      }
    }
    span {
      font-size: 14px;
    }
  }
  .property {
    font-size: 12px;
    color: $gray;
    span {
      margin-right: 5px;
    }
  }
  .status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    span {
      &:first-child {
        color: $grey;
        font-size: 14px;
      }
    }
  }
  .red {
    color: $red;
  }
  .green {
    color: $green;
  }
</style>
